<?php
/*
 * class.adminuser.php
 * 文件说明:管理员用户模块
 * @version 0.1
 * @author samuel
 * @date 2009-05-06
 */
include_once 'class.user.php';

class adminuser extends user {

    private $core;

	function  __construct( $params ) {
        $this->core = $GLOBALS['CORE'];
		$this->username = $this->core->db->quote($params['username']);
		$this->password = $this->core->db->quote($params['password']);
	}

	public function login(){
		
	}

	public function logout(){
		session_unset();
	}

	public function validateLogin(){
		$sql = "SELECT `admin_id`, `admin_username`, `admin_status` FROM `admin_member` WHERE `admin_username`='".$this->username."' AND `admin_password`='".$this->password."'";
        $res = $this->core->db->get_row($sql);
        $admin_id = $res->admin_id;
        $admin_username = $res->admin_username;
        $admin_status = $res->admin_status;

        if(!$admin_id){
            return 0;
        }elseif(!$admin_status){
            return -1;
        }else{
            $_SESSION['admin_id']       = $admin_id;
            $_SESSION['admin_username'] = $admin_username;
            $_SESSION['admin_status']   = $admin_status;
            return 1;
        }
	}

    public function updateLoginStatus(){
        $loginIP = $_SERVER['REMOTE_ADDR'];
        $sessionid = session_id();
        $admin_id = $_SESSION['admin_id'];
        $sql = "UPDATE `admin_member` SET `admin_lastLogin`=".time().", `admin_lastIP`='".$loginIP."', `admin_sessionid`='".$sessionid."' WHERE `admin_id`=" . $admin_id;
        $res = $this->core->db->query($sql);
        return $res;
    }

	public function register(){
		
	}
	
}
?>
